/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace DaveSexton.DocProject.Sandcastle.TopicManagement
{
	internal sealed class TopicManagementDialogSettings : DialogSettings<TopicManagementDialog>
	{
		#region Public Properties
		public static readonly Guid DialogGuid = new Guid("38889CD0-882C-46fd-B63A-94155A409F49");

		public int TopicExplorerWidth
		{
			get
			{
				return Read("topicExplorerWidth", 0);
			}
			set
			{
				Write("topicExplorerWidth", value);
			}
		}

		public int TopicEditorListWidth
		{
			get
			{
				return Read("topicEditorListWidth", 0);
			}
			set
			{
				Write("topicEditorListWidth", value);
			}
		}
		#endregion

		#region Private / Protected
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="TopicManagementDialogSettings" /> class.
		/// </summary>
		public TopicManagementDialogSettings(TopicManagementDialog dialog)
			: base(dialog, DialogGuid)
		{
			dialog.TopicEditorListWidthChanged += dialog_TopicEditorListWidthChanged;
			dialog.TopicExplorerWidthChanged += dialog_TopicExplorerWidthChanged;
		}
		#endregion

		#region Methods
		protected override void LoadInternal()
		{
			int topicExplorerWidth = this.TopicExplorerWidth;

			if (topicExplorerWidth > 0)
			{
				try
				{
					Dialog.TopicExplorerWidth = topicExplorerWidth;
				}
				catch (InvalidOperationException) { this.TopicExplorerWidth = Dialog.TopicExplorerWidth; }
				catch (ArgumentException) { this.TopicExplorerWidth = Dialog.TopicExplorerWidth; }
			}

			int topicEditorListWidth = this.TopicEditorListWidth;

			if (topicEditorListWidth > 0)
			{
				try
				{
					Dialog.TopicEditorListWidth = topicEditorListWidth;
				}
				catch (InvalidOperationException) { this.TopicEditorListWidth = Dialog.TopicEditorListWidth; }
				catch (ArgumentException) { this.TopicEditorListWidth = Dialog.TopicEditorListWidth; }
			}
		}
		#endregion

		#region Event Handlers
		private void dialog_TopicExplorerWidthChanged(object sender, EventArgs e)
		{
			if (!Loading)
				this.TopicExplorerWidth = Dialog.TopicExplorerWidth;
		}

		private void dialog_TopicEditorListWidthChanged(object sender, EventArgs e)
		{
			if (!Loading)
				this.TopicEditorListWidth = Dialog.TopicEditorListWidth;
		}
		#endregion
	}
}
